package due.pc.pcshoot.control;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.camera.hud.HUD;
import org.anddev.andengine.engine.handler.timer.ITimerCallback;
import org.anddev.andengine.engine.handler.timer.TimerHandler;
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.opengl.font.StrokeFont;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;

import android.graphics.Color;
import android.graphics.Typeface;

public class PlayerScene extends HUD {

	public static final int FONT_SIZE = 32;

	public static final int SCORESTEXT_X = 440;
	public static final int SCORESTEXT_Y = 0;
	public static final int LIVESTEXT_X = 440;
	public static final int LIVESTEXT_Y = 40;

	private Player mplayer;
	private Engine mEngine;
	
	private Texture mFontTexture;
	private StrokeFont mStrokeFont;
	private ChangeableText mLivesText, mScoresText;

	public PlayerScene(Engine engine, Camera camera, Player player) {
		mEngine = engine;
		setCamera(camera);
		mplayer = player;
		
		
		mFontTexture = new Texture(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		mStrokeFont = new StrokeFont(mFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), FONT_SIZE, true, Color.BLACK, 2, Color.WHITE);
		mEngine.getTextureManager().loadTextures(mFontTexture);
		mEngine.getFontManager().loadFonts(mStrokeFont);
		
		
		mLivesText = new ChangeableText(LIVESTEXT_X, LIVESTEXT_Y, mStrokeFont, "Live:", "Lives: XXXXXXX".length());
		mLivesText.setAlpha(0.2f);
		attachChild(mLivesText);
		
		mScoresText = new ChangeableText(SCORESTEXT_X, SCORESTEXT_Y, mStrokeFont, "Score:", "Score: XXXXXX".length());
		mScoresText.setAlpha(0.2f);
		attachChild(mScoresText);
		
		
		registerUpdateHandler(new TimerHandler(0.1f, true,
				new ITimerCallback() {
					@Override
					public void onTimePassed(TimerHandler pTimerHandler) {
						mScoresText.setText("Score: " + PlayerScene.this.mplayer.getScores());
						mLivesText.setText("Live: " + PlayerScene.this.mplayer.getLives());
					}
				}));
	}
}
